markdown-up 3.3.4 → 3.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/lineChart.js +20 -2
  2. package/package.json +1 -1
package/lib/lineChart.js CHANGED
@@ -41,6 +41,9 @@ struct LineChart
41
41
  # The color encoding field
42
42
  optional string color
43
43
 
44
+ # The color encoding value order
45
+ optional string[len > 0] colorOrder
46
+
44
47
  # The X-axis tick marks
45
48
  optional LineChartAxisTicks xTicks
46
49
 
@@ -180,6 +183,7 @@ export function lineChartElements(data, lineChart, options = null) {
180
183
  const xField = lineChart.x;
181
184
  const yFields = lineChart.y;
182
185
  const colorField = lineChart.color ?? null;
186
+ const colorOrder = lineChart.colorOrder ?? null;
183
187
 
184
188
  // Sort the rows by the X field
185
189
  data.sort((row1, row2) => {
@@ -219,7 +223,21 @@ export function lineChartElements(data, lineChart, options = null) {
219
223
  }
220
224
 
221
225
  // Add the points
222
- const colorValues = Array.from(colorValueSet.values()).sort();
226
+ let colorValues;
227
+ if (colorOrder !== null) {
228
+ colorValues = Array.from(colorValueSet.values()).sort((cv1, cv2) => {
229
+ const ix1 = colorOrder.indexOf(cv1);
230
+ const ix2 = colorOrder.indexOf(cv2);
231
+ if (ix1 !== -1 && ix2 !== -1) {
232
+ return ix1 < ix2 ? -1 : 1;
233
+ } else if (ix1 === -1 && ix2 === -1) {
234
+ return cv1 < cv2 ? -1 : 1;
235
+ }
236
+ return ix1 !== -1 ? -1 : 1;
237
+ });
238
+ } else {
239
+ colorValues = Array.from(colorValueSet.values()).sort();
240
+ }
223
241
  const colorValueCount = colorValues.length;
224
242
  for (let ixColorValue = 0; ixColorValue < colorValueCount; ixColorValue += 1) {
225
243
  const colorValue = colorValues[ixColorValue];
@@ -364,7 +382,7 @@ export function lineChartElements(data, lineChart, options = null) {
364
382
  const labelWidth = label.length * chartFontWidthRatio * colorLegendFontSize;
365
383
  return labelWidth > labelMax ? labelWidth : labelMax;
366
384
  }, 0);
367
- const colorLegendX = yFields.length === 1 && !('color' in lineChart) ? null : Math.max(
385
+ const colorLegendX = yFields.length === 1 && colorField === null ? null : Math.max(
368
386
  chartWidth - chartBorderSize - colorLegendLabelWidth - colorLegendSampleWidth,
369
387
  0.6 * chartWidth
370
388
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "3.3.4",
4
+ "version": "3.3.5",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",