Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a stroke-width configuration to lineSeries d3fc charts #2920

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/perspective/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ if(PSP_WASM_BUILD)
-g3 \
-Wcast-align \
-Wover-aligned \
--emit-tsd=perspective-server.d.ts \
")
if (PSP_WASM_EXCEPTIONS)
set(OPT_FLAGS "${OPT_FLAGS} -fwasm-exceptions ")
Expand Down
18 changes: 16 additions & 2 deletions packages/perspective-viewer-d3fc/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function add(builder, path) {
);
}

async function compile_css() {
function compile_css() {
fs.mkdirSync("dist/css", { recursive: true });
const builder = new BuildCss("");
add(builder, "./series_colors.less");
Expand All @@ -94,10 +94,24 @@ async function compile_css() {
);
}

function move_html() {
fs.mkdirSync("dist/html", { recursive: true });

const srcDir = "src/html";
const destDir = "dist/html";

fs.readdirSync(srcDir).forEach((file) => {
const srcFile = `${srcDir}/${file}`;
const destFile = `${destDir}/${file}`;
fs.copyFileSync(srcFile, destFile);
});
}

async function build_all() {
// NOTE: compile_css and other build step must be run before tsc, because
// (for now) nothing runs after the tsc step.
await compile_css();
compile_css();
move_html();
await Promise.all(BUILD.map(build)).catch(() => process.exit(1));

// esbuild can handle typescript files, and strips out types from the output,
Expand Down
18 changes: 12 additions & 6 deletions packages/perspective-viewer-d3fc/src/ts/series/lineSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import * as fc from "d3fc";
import { withoutOpacity } from "./seriesColors.js";
import { D3Scale, Settings } from "../types.js";

export function lineSeries(settings: Settings, color: D3Scale) {
export function lineSeries(
settings: Settings,
color: D3Scale,
stroke_width: number | undefined = undefined
) {
let series = fc.seriesSvgLine();

const estimated_size =
Expand All @@ -23,15 +27,17 @@ export function lineSeries(settings: Settings, color: D3Scale) {
? Object.keys(settings.data[0]).length -
(settings.crossValues?.length > 0 ? 1 : 0)
: 0);
const stroke_width = Math.max(
1,
Math.min(3, Math.floor(settings.size.width / estimated_size / 2))
);
const width =
stroke_width ??
Math.max(
1,
Math.min(3, Math.floor(settings.size.width / estimated_size / 2))
);

series = series.decorate((selection) => {
selection
.style("stroke", (d) => withoutOpacity(color(d[0] && d[0].key)))
.style("stroke-width", stroke_width);
.style("stroke-width", width);
});

return series.crossValue((d) => d.crossValue).mainValue((d) => d.mainValue);
Expand Down
Loading