Skip to content

Commit 4082261

Browse files
Merge pull request #8 from mindthemath/hotfix/flash
fix more UI issues
2 parents 70a046f + ff3df78 commit 4082261

6 files changed

Lines changed: 292 additions & 31 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "hiplot-mm"
7-
version = "0.0.4rc12"
7+
version = "0.0.4rc13"
88
description = "High dimensional Interactive Plotting tool"
99
readme = "README.md"
1010
license = "MIT"

src/parallel/parallel.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -974,27 +974,13 @@ export class ParallelPlot extends React.Component<ParallelPlotData, ParallelPlot
974974
});
975975
}
976976

977-
// show ticks
978-
div.selectAll("." + pstyle.axis + " g").style("display", null);
979-
div.selectAll(".background").style("visibility", null);
980-
981977
// update axes
982978
div.selectAll("." + pstyle.axis).each((d: string, i, nodes) => {
983979
const node = nodes[i];
984-
// hide lines for better performance
985-
d3.select(node).selectAll("line").style("display", "none");
986-
987980
// transition axis numbers
988981
d3.select(node).transition().duration(720).call(this.get_axis(d));
989982

990-
// bring lines back
991-
d3.select(node).selectAll("line").transition().delay(800).style("display", null);
992-
993-
d3.select(node)
994-
.selectAll("text")
995-
.style("font-weight", null)
996-
.style("font-size", null)
997-
.style("display", null);
983+
d3.select(node).selectAll(".tick text").style("font-weight", null).style("font-size", null);
998984
});
999985
this.setState(function (prevState) {
1000986
return { brush_count: prevState.brush_count + 1 };

src/plotxy.tsx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,16 @@ export class PlotXY extends React.Component<PlotXYProps, PlotXYState> {
192192
if (!paramDef) {
193193
return null;
194194
}
195+
if (paramDef.type === ParamType.TIMESTAMP) {
196+
return null;
197+
}
195198
if (paramDef.ticks_format) {
196199
return d3.format(paramDef.ticks_format);
197200
}
198201
const isNumericLike =
199202
paramDef.type === ParamType.NUMERIC ||
200203
paramDef.type === ParamType.NUMERICLOG ||
201-
paramDef.type === ParamType.NUMERICPERCENTILE ||
202-
paramDef.type === ParamType.TIMESTAMP;
204+
paramDef.type === ParamType.NUMERICPERCENTILE;
203205
if (!isNumericLike || typeof scale.domain !== "function") {
204206
return null;
205207
}
@@ -215,6 +217,28 @@ export class PlotXY extends React.Component<PlotXYProps, PlotXYState> {
215217
}
216218
return d3.format(".3~e");
217219
}
220+
function getTickValues(param: string, scale: any, approxTickCount: number): any[] | null {
221+
const paramDef = me.props.params_def[param];
222+
if (
223+
!paramDef ||
224+
paramDef.type !== ParamType.NUMERICLOG ||
225+
typeof scale.ticks !== "function"
226+
) {
227+
return null;
228+
}
229+
const ticks = scale.ticks(approxTickCount);
230+
if (!Array.isArray(ticks)) {
231+
return null;
232+
}
233+
const majorTicks = ticks.filter((tick: number) => {
234+
if (!Number.isFinite(tick) || tick <= 0) {
235+
return false;
236+
}
237+
const lg = Math.log10(tick);
238+
return Math.abs(lg - Math.round(lg)) < 1e-10;
239+
});
240+
return majorTicks.length > 1 ? majorTicks : null;
241+
}
218242
function redraw_axis() {
219243
me.svg.selectAll(".axis_render").remove();
220244
me.svg.selectAll(".brush").remove();
@@ -242,6 +266,10 @@ export class PlotXY extends React.Component<PlotXYProps, PlotXYState> {
242266
]);
243267
const xTickFormatter = getTickFormatter(me.state.axis_x, x_scale);
244268
const yTickFormatter = getTickFormatter(me.state.axis_y, y_scale);
269+
const yTickCount = 1 + me.state.height / 40;
270+
const xTickCount = 1 + me.state.width / 80;
271+
const xTickValues = getTickValues(me.state.axis_x, x_scale, xTickCount);
272+
const yTickValues = getTickValues(me.state.axis_y, y_scale, yTickCount);
245273
zoom_brush = d3
246274
.brush()
247275
.extent([
@@ -256,7 +284,8 @@ export class PlotXY extends React.Component<PlotXYProps, PlotXYState> {
256284
.call(
257285
d3
258286
.axisLeft(y_scale)
259-
.ticks(1 + me.state.height / 40)
287+
.ticks(yTickCount)
288+
.tickValues(yTickValues as any)
260289
.tickFormat(yTickFormatter as any)
261290
.tickSizeInner(margin.left + margin.right - me.state.width),
262291
)
@@ -289,7 +318,8 @@ export class PlotXY extends React.Component<PlotXYProps, PlotXYState> {
289318
.call(
290319
d3
291320
.axisBottom(x_scale)
292-
.ticks(1 + me.state.width / 80)
321+
.ticks(xTickCount)
322+
.tickValues(xTickValues as any)
293323
.tickFormat(xTickFormatter as any)
294324
.tickSizeInner(margin.bottom + margin.top - me.state.height),
295325
)

src/rowsdisplaytable.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ export class RowsDisplayTable extends React.Component<TablePluginProps, RowsDisp
6969

7070
setSelected_debounced = _.debounce(this.setSelected, 150);
7171

72+
private getUidFromRowData(rowData: Array<any>): string {
73+
const uidIdx = this.ordered_cols.indexOf("uid");
74+
if (uidIdx >= 0) {
75+
const direct = rowData[uidIdx];
76+
if (this.props.dp_lookup[direct] !== undefined) {
77+
return direct;
78+
}
79+
if (this.dt && this.dt.colReorder) {
80+
const reorderedUidIdx = this.dt.colReorder.order().indexOf(uidIdx);
81+
const remapped = rowData[reorderedUidIdx];
82+
if (this.props.dp_lookup[remapped] !== undefined) {
83+
return remapped;
84+
}
85+
}
86+
}
87+
return rowData[uidIdx];
88+
}
89+
7290
static defaultProps = {
7391
hide: [],
7492
order_by: [["uid", "asc"]],
@@ -110,7 +128,6 @@ export class RowsDisplayTable extends React.Component<TablePluginProps, RowsDisp
110128
});
111129
}
112130
me.ordered_cols.unshift("");
113-
const uidColIndex = me.ordered_cols.indexOf("uid");
114131

115132
dom.empty();
116133
var columns: Array<{ [k: string]: any }> = this.ordered_cols.map(function (x) {
@@ -138,8 +155,8 @@ export class RowsDisplayTable extends React.Component<TablePluginProps, RowsDisp
138155
if (!me.dt) {
139156
return "";
140157
}
141-
const individualUidColIdx = me.dt.colReorder.order().indexOf(uidColIndex);
142-
const color = me.props.get_color_for_row(me.props.dp_lookup[row[individualUidColIdx]], 1.0);
158+
const uid = me.getUidFromRowData(row);
159+
const color = me.props.get_color_for_row(me.props.dp_lookup[uid], 1.0);
143160
return `<span class="${style.colorBlock}" style="background-color: ${color}" />`;
144161
};
145162
this.dt = dom.DataTable({
@@ -206,14 +223,13 @@ export class RowsDisplayTable extends React.Component<TablePluginProps, RowsDisp
206223
}
207224
const rowIdx = me.dt.cell(this).index().row;
208225
const row = me.dt.row(rowIdx);
209-
const individualUidColIdx = me.dt.colReorder.order().indexOf(uidColIndex);
210226

211227
dom.find(`.table-primary`).removeClass("table-primary");
212228
const rowNode = row.node();
213229
if (rowNode) {
214230
$(rowNode).addClass("table-primary");
215231
}
216-
me.props.setHighlighted([me.props.dp_lookup[row.data()[individualUidColIdx]]]);
232+
me.props.setHighlighted([me.props.dp_lookup[me.getUidFromRowData(row.data())]]);
217233
})
218234
.on("mouseout", "td", function () {
219235
if (!me.dt || me.empty) {
@@ -302,15 +318,11 @@ export class RowsDisplayTable extends React.Component<TablePluginProps, RowsDisp
302318
return;
303319
}
304320
const ordered_cols = this.ordered_cols;
305-
const ock = dt.colReorder.transpose(
306-
Array.from(Array(ordered_cols.length).keys()),
307-
"toOriginal",
308-
);
309321

310322
dt.clear();
311323
dt.rows.add(
312324
selected.map(function (row) {
313-
return ock.map((x) => (x == "" ? "" : row[ordered_cols[x]]));
325+
return ordered_cols.map((col) => (col == "" ? "" : row[col]));
314326
}),
315327
);
316328
if (dt.search() == "") {

0 commit comments

Comments
 (0)