Fill area above line in AmCharts - amcharts
I'm plotting threshold violations. In some cases, thresholds are violated when the values are above the threshold. In this case, I fill the area below the line, like so:
However, in cases where values violate the threshold when they are below it, I want to fill the area above the line. Because I don't know how, the below image looks a bit weird. It'd be better if only the big dip at the beginning was in red. Like the reverse effect of the first image.
How can I fill the area above a line chart in AmCharts 3?
My current configuration (excuse the PHP, my frontend app eats JSON):
array(
'id' => 'major',
'valueAxis' => 'result',
'valueField' => 'result',
'type' => 'smoothedLine',
'lineThickness' => 2,
'lineAlpha' => 1,
'lineColor' => $threshold_at_top ? 'gold' : 'crimson',
'fillAlphas' => $threshold_at_top ? 0.001 : 0.1,
'negativeLineAlpha' => 1,
'negativeLineColor' => $threshold_at_top ? 'crimson' : 'gold',
'negativeFillAlphas' => $threshold_at_top ? 0.1 : 0.001,
'negativeBase' => $threshold_major,
'bullet' => 'none',
'balloon' => array(
'enabled' => false
)
),
array(
'id' => 'minor',
'valueAxis' => 'result',
'valueField' => 'result',
'type' => 'smoothedLine',
'lineThickness' => 2,
'lineAlpha' => $threshold_at_top ? 1 : 0,
'lineColor' => $threshold_at_top ? 'teal' : 'crimson',
'fillAlphas' => $threshold_at_top ? 0.001 : 0.1,
'negativeLineAlpha' => $threshold_at_top ? 0 : 1,
'negativeLineColor' => $threshold_at_top ? 'crimson' : 'teal',
'negativeFillAlphas' => $threshold_at_top ? 0.1 : 0.001,
'negativeBase' => $threshold_minor,
'bullet' => 'none',
'balloonText' => '<b>Result</b><br /><span style="font-size:1.5em;">[[value]]' . ( $last_datapoint->is_percentage ? ' %' : '' ) . '</span>',
'balloon' => array(
'adjustBorderColor' => false,
'color' => '#f1f1f1',
'fillColor' => '#2d87c3'
)
)
minor is the same line chart drawn on top of major.
What I've tried so far
When $threshold_at_top == true, I add another (invisible) top graph, which is simply the same value at each datapoint. This value is above all other values of the other graphs. For example, when I'm plotting a graph with results between 0 and 100, I plot this hidden top graph at 100.
Then I add it to the graphs object (as first element):
array_unshift( $options[ 'graphs' ], array(
'id' => 'top',
'valueAxis' => 'result',
'valueField' => 'top',
'type' => 'smoothedLine',
'lineAlpha' => 0,
'fillAlphas' => 0,
'bullet' => 'none',
'balloon' => array(
'enabled' => false
)
));
Then, I tell my existing major and minor graphs to 'fillToGraph' : 'top':
$options[ 'graphs' ][ 3 ][ 'fillToGraph' ] = 'top';
$options[ 'graphs' ][ 4 ][ 'fillToGraph' ] = 'top';
This gives the desired effect, but only when zoomed in enough:
When scrolling the same chart further to the right, new datapoints come into view, and it somehow messes up the area filled:
I reached out to AmCharts support, and they confirmed my suspicion (emphasis mine):
I checked with colleagues and I just wanted to let you know that
regular line graphs can support both fillToGraph and negativeFill at
the same time. You can see this behavior in the example below:
https://codepen.io/team/amcharts/pen/f8d6c8c5d3a2b4550a2b99f7486355e5?editors=0010
"graphs": [{
"id": "fromGraph",
"fillAlphas": 0.2,
"fillToGraph": "toGraph",
//"type": "smoothedLine",
"lineAlpha": 1,
"showBalloon": false,
"valueField": "fromValue",
"negativeBase": 40,
"negativeLineColor": "crimson"
}...
Therefore, we suggest using regular lines instead of smoothedLines, if
at all possible.
It's not possible to create my desired effect using smoothedLine graphs. See the bug below:
Related
JBoss pool has negative value for IdleCount
Sometimes, when checking my JBoss 7.1 connection pool status (JDBC), I see a negative value for IdleCount, like in the following example where "IdleCount" => -7. Can someone explain me the meaning of this negative value? "pool" => { "ActiveCount" => 13, "AvailableCount" => 230, "AverageBlockingTime" => 1L, "AverageCreationTime" => 76L, "AverageGetTime" => 2L, "AveragePoolTime" => 306L, "AverageUsageTime" => 241L, "BlockingFailureCount" => 0, "CreatedCount" => 13, "DestroyedCount" => 0, "IdleCount" => -7, "InUseCount" => 20,
IdleCount is calculated using ActiveCout - InUseCount. e.g. IdleCount = ActiveCount - InUseCount => 13-20 = -7 That is why it is showing -7 in the pool stats. refer to the code base
Perl TK - Wrap text in an Entry widget
I created a table that contains a "Key" column, "Value" column and a "New Value" column as shown in the image below. The "Key" and "Value" columns are implemented as Labels, the "Value" column is wrapped as you can see. The "New Value" column is implemented as an Entry widget because it should be editable. There is a Copy & Paste button that copies the value to the "New Value" Entry field. I would like to wrap the text in the Entry widget, so after pressing the button it will look like the text in the "Value" field. Image that shows the table I built and the difference between the wrapped Label to the text in the Entry field Here is the piece of code that defines the shown columns: my $key_label = $table->Label(-text => $key , -width => 50, -bg => $background_color, -anchor => 'w', -relief => $relief_style, -wraplength => 300)->pack(-side => 'left'); $table->put($curr_row,1,$key_label); my $orig_val_label = $table->Label(-text => $full_cfg_hash{$key}{'old_value'}, -width => 50, -bg => $background_color, -anchor => 'w', -relief => $relief_style, -wraplength => 300)->pack(-side => 'left'); $table->put($curr_row,2,$orig_val_label); my $new_val_entry = $table->Entry(-text => $full_cfg_hash{$key}{'new_value'}, -width => $entry_size, -bg => $background_color)->pack( -side => 'left', -fill => 'both', -expand => 'yes'); $table->put($curr_row,3,$new_val_entry); my $copy_paste_btn = $table->Button(-text => "Copy & Edit\nOld Value", -command => [\©_n_edit_old_value,$full_cfg_hash{$key}{'old_value'},$new_val_entry], -bg => $buttons_background, -foreground => $buttons_text_color)->pack(-side => 'left', -padx => 5); $table->put($curr_row,4,$copy_paste_btn);
The Tk::Text widget is for multi-line text entry, usually combined with Tk::Scrolled, something like: my $new_val_entry = $table->Scrolled( 'Text', -width => 40, -height => 3, -wrap => 'word', -scrollbars => 'e', -font => $my_font, )->pack( -expand => 1, -fill => 'both', -padx => 5, -pady => 5, );
Smarty assign, calculate 10%
Need help please! In prestashop I want to add of value of 10% calculated from total_to_pay Can any one help me to add this ? $this->smarty->assign(array( 'total_to_pay' => Tools::displayPrice($params['total_to_pay'], $params['currencyObj'], false), 'chequeName' => $this->chequeName, 'chequeAddress' => Tools::nl2br($this->address), 'status' => 'ok', 'id_order' => $params['objOrder']->id ));
Something like this to a 10% 'total_to_pay' => Tools::displayPrice($stats_sales['sales'] * 10 / 100, $params['currencyObj'], false)
Normalize British and American English for Elasticsearch
Is there a best practice for normalizing British and American English in Elasticsearch? Using a Synonym Token Filter requires an incredibly long configuration file. There are actually several thousand differently spelled words in UK and US English and it's almost impossible to find a really comprehensive list of words. Here's a list of almost 2.000 words, but it's far from being complete. Preferably, I'd like to create an ES Analyzer/Filter with rules to transform US to UK English. Maybe that's the better approach, but I don't know where to start - which type of filters do I need for that? It doesn't have to cover everything - it should merely normalize most search terms. E.g. "grey" - "gray", "colour" - "color", "center" - "centre", etc.
Here's the approach I went for after fiddling around a while. It's a combination of basic rules, "fixes", and synonyms: First, apply a char_filter to enforce a set of basic spelling rules. It's not 100% correct, but it does the job pretty well: "char_filter": { "en_char_filter": { "type": "mapping", "mappings": [ # fixes "aerie=>axerie", "aeroplane=>airplane", "aloe=>aloxe", "canoe=>canoxe", "coerce=>coxerce", "poem=>poxem", "prise=>prixse", # whole words "armour=>armor", "behaviour=>behavior", "centre=>center" "colour=>color", "clamour=>clamor", "draught=>draft", "endeavour=>endeavor", "favour=>favor", "flavour=>flavor", "harbour=>harbor", "honour=>honor", "humour=>humor", "labour=>labor", "litre=>liter", "metre=>meter", "mould=>mold", "neighbour=>neighbor", "plough=>plow", "saviour=>savior", "savour=>savor", # generic transformations "ae=>e", "ction=>xion", "disc=>disk", "gramme=>gram", "isable=>izable", "isation=>ization", "ise=>ize", "ising=>izing", "ll=>l", "oe=>e", "ogue=>og", "sation=>zation", "yse=>yze", "ysing=>yzing" ] } } The "fixes" entry is there to prevent incorrect application of other rules. E.g. "prise=>prixse" prevents "prise" from getting changed into "prize", which has a different meaning. You may need to adapt this according to your own needs. Next, include a synonym filter for catching the most frequently used exceptions: "en_synonym_filter": { "type": "synonym", "synonyms": EN_SYNONYMS } Here's our list of synonyms that includes the most important keywords for our use case. You may wish to adapt this list to your needs: EN_SYNONYMS = ( "accolade, prize => award", "accoutrement => accouterment", "aching, pain => hurt", "acw, anticlockwise, counterclockwise, counter-clockwise => ccw", "adaptor => adapter", "advocate, attorney, barrister, procurator, solicitor => lawyer", "ageing => aging", "agendas, agendum => agenda", "almanack => almanac", "aluminium => aluminum", "america, united states, usa", "amphitheatre => amphitheater", "anti-aliased, anti-aliasing => antialiased", "arbour => arbor", "ardour => ardor", "arse => ass", "artefact => artifact", "aubergine => eggplant", "automobile, motorcar => car", "axe => ax", "bannister => banister", "barbecue => bbq", "battleaxe => battleax", "baulk => balk", "beetroot => beet", "biassed => biased", "biassing => biasing", "biscuit => cookie", "black american, african american, afro-american, negro", "bobsleigh => bobsled", "bonnet => hood", "bulb, electric bulb, light bulb, lightbulb", "burned => burnt", "bussines, bussiness => business", "business man, business people, businessman", "business woman, business people, businesswoman", "bussing => busing", "cactus, cactuses => cacti", "calibre => caliber", "candour => candor", "candy floss, candyfloss, cotton candy", "car park, parking area, parking ground, parking lot, parking-lot, parking place, parking", "carburettor => carburetor", "castor => caster", "cataloguing => cataloging", "catboat, sailboat, sailing boat", "champion, gainer, victor, win, winner => victory", "chat => talk", "chequebook => checkbook", "chequer => checker", "chequerboard => checkerboard", "chequered => checkered", "christmas tree ball, christmas tree ball ornament, christmas ball ornament, christmas bauble", "christmas, x-mas => xmas", "cinema => movies", "clangour => clangor", "clarinettist => clarinetist", "conditioning => conditioner", "conference => meeting", "coriander => cilantro", "corporate => company", "cosmos, universe => outer space", "cosy, cosiness => cozy", "criminal => crime", "curriculums => curricula", "cypher => cipher", "daddy, father, pa, papa => dad", "defence => defense", "defenceless => defenseless", "demeanour => demeanor", "departure platform, station platform, train platform, train station", "dishrag => dish cloth", "dishtowel, dishcloth => dish towel", "doughnut => donut", "downspout => drainpipe", "drugstore => pharmacy", "e-mail => email", "enamoured => enamored", "england => britain", "english => british", "epaulette => epaulet", "exercise, excercise, training, workout => fitness", "expressway, motorway, highway => freeway", "facebook => facebook, social media", "fanny => buttocks", "fanny pack => bum bag", "farmyard => barnyard", "faucet => tap", "fervour => fervor", "fibre => fiber", "fibreglass => fiberglass", "flashlight => torch", "flautist => flutist", "flier => flyer", "flower fly, hoverfly, syrphid fly, syrphus fly", "foot-walk, sidewalk, sideway => pavement", "football, soccer", "forums => fora", "fourth => 4", "freshman => fresher", "chips, fries, french fries", "gaol => jail", "gaolbird => jailbird", "gaolbreak => jailbreak", "gaoler => jailer", "garbage, rubbish => trash", "gasoline => petrol", "gases, gasses", "gauge => gage", "gauged => gaged", "gauging => gaging", "gipsy, gipsies, gypsies => gypsy", "glamour => glamor", "glueing => gluing", "gravesite, sepulchre, sepulture => sepulcher", "grey => gray", "greyish => grayish", "greyness => grayness", "groyne => groin", "gryphon, griffon => griffin", "hand shake, shake hands, shaking hands, handshake", "haulier => hauler", "hobo, homeless, tramp => bum", "new year, new year's eve, hogmanay, silvester, sylvester", "holiday => vacation", "holidaymaker, holiday-maker, vacationer, vacationist => tourist", "homosexual, fag => gay", "inbox, letterbox, outbox, postbox => mailbox", "independence day, 4th of july, fourth of july, july 4th, july 4, 4th july, july fourth, forth of july, 4 july, fourth july, 4th july", "infant, suckling, toddler => baby", "infeasible => unfeasible", "inquire, inquiry => enquire", "insure => ensure", "internet, website => www", "jelly => jam", "jewelery, jewellery => jewelry", "jogging => running", "journey => travel", "judgement => judgment", "kerb => curb", "kiwifruit => kiwi", "laborer => worker", "lacklustre => lackluster", "ladybeetle, ladybird, ladybug => ladybird beetle", "larrikin, scalawag, rascal, scallywag => naughty boy", "leaf => leaves", "licence, licenced, licencing => license", "liquorice => licorice", "lorry => truck", "loupe, magnifier, magnifying, magnifying glass, magnifying lens, zoom", "louvred => louvered", "louvres => louver", "lustre => luster", "mail => post", "mailman => postman", "marriage, married, marry, marrying, wedding => wed", "mayonaise => mayo", "meagre => meager", "misdemeanour => misdemeanor", "mitre => miter", "mom, momma, mummy, mother => mum", "moonlight => moon light", "moult => molt", "moustache, moustached => mustache", "nappy => diaper", "nightlife => night life", "normalcy => normality", "octopus => kraken", "odour => odor", "odourless => odorless", "offence => offense", "omelette => omelet", "# fix torres del paine", "paine => painee", "pajamas => pyjamas", "pantyhose => tights", "parenthesis, parentheses => bracket", "parliament => congress", "parlour => parlor", "persnickety => pernickety", "philtre => filter", "phoney => phony", "popsicle => iced-lolly", "porch => veranda", "pretence => pretense", "pullover, jumper => sweater", "pyjama => pajama", "railway => railroad", "rancour => rancor", "rappel => abseil", "row house, serial house, terrace house, terraced house, terraced housing, town house", "rigour => rigor", "rumour => rumor", "sabre => saber", "saltpetre => saltpeter", "sanitarium => sanatorium", "santa, santa claus, st nicholas, st nicholas day", "sceptic, sceptical, scepticism, sceptics => skeptic", "sceptre => scepter", "shaikh, sheikh => sheik", "shivaree => charivari", "silverware, flatware => cutlery", "simultaneous => simultanous", "sleigh => sled", "smoulder, smouldering => smolder", "sombre => somber", "speciality => specialty", "spectre => specter", "splendour => splendor", "spoilt => spoiled", "street => road", "streetcar, tramway, tram => trolley-car", "succour => succor", "sulphate, sulphide, sulphur, sulphurous, sulfurous => sulfur", "super hero, superhero => hero", "surname => last name", "sweets => candy", "syphon => siphon", "syphoning => siphoning", "tack, thumb-tack, thumbtack => drawing pin", "tailpipe => exhaust pipe", "taleban => taliban", "teenager => teen", "television => tv", "thank you, thanks", "theatre => theater", "tickbox => checkbox", "ticked => checked", "timetable => schedule", "tinned => canned", "titbit => tidbit", "toffee => taffy", "tonne => ton", "transportation => transport", "trapezium => trapezoid", "trousers => pants", "tumour => tumor", "twitter => twitter, social media", "tyre => tire", "tyres => tires", "undershirt => singlet", "university => college", "upmarket => upscale", "valour => valor", "vapour => vapor", "vigour => vigor", "waggon => wagon", "windscreen, windshield => front shield", "world championship, world cup, worldcup", "worshipper, worshipping => worshiping", "yoghourt, yoghurt => yogurt", "zip, zip code, postal code, postcode", "zucchini => courgette" )
I realize that this answer departs somewhat from the OP's initial question, but if you just want to normalize American vs. British English spelling variants, you can look here for a manageably sized list (~1,700 replacements): http://www.tysto.com/uk-us-spelling-list.html. I'm sure there are others out there too that you could use to create a consolidated master list. Apart from spelling variation, you must be very careful not to blithely replace words in isolation with their (assumed!) counterparts in American English. I would advise against all but the most solid of lexical replacements. E.g., I can't see anything bad happening from this one "anticlockwise, counterclockwise, counter-clockwise => counter-clockwise" but this one "hobo, homeless, tramp => bum" would index "A homeless man" => *"A bum man", which is nonsense. (Not to mention that hobos, the homeless and "tramps" are quite distinct -- http://knowledgenuts.com/2014/11/26/the-difference-between-hobos-tramps-and-bums/.) In summary, apart from spelling variation, the American vs. British dialect divide is complicated and cannot be reduced to simple list look-ups. P.S. If you really want to do this right (i.e., account for grammatical context, etc.), you would probably need a context-sensitive paraphrase model to "translate" British to American English (or the inverse, depending on your needs) before it ever hits the ES index. This could be done (with sufficient parallel data) using an off-the-shelf statistical translation model, or maybe even some custom, in-house software that uses natural language parsing, POS tagging, chunking, etc.
Zend Framework Validate field is integer between 1 and 5
I use Zend\InputFilter\InputFilter class for form validation. point field should accept only integers between 1 and 5. But it doesn't work properly it accepts string starting with integers between 1 and 5. For example 1kjhkjh, 2tgfjhgfjhf, 4jhkljg... What is wrong in my code? $inputFilter->add ( $inputFilter->getFactory()->createInput ( array ( 'name' => 'point', 'required' => true, 'validators' => array ( array( 'name' => 'Digits'), array ( 'name' => 'Between', 'options' => array ( 'min' => 1, 'max' => 5, 'messages' => array('notBetween' => 'Point must be between %min% and %max%') ) ) ) ) ) );
Use the the second parameter of zend validator to break the validators chain and return an error, breakChainOnFailure (documentation) tells the element to stop validating if this error is triggered, so in your case if it is not a digit the user gets an error, when the user has fixed the error the second validator will get triggered too: $inputFilter->add ( $inputFilter->getFactory()->createInput ( array ( 'name' => 'point', 'required' => true, 'validators' => array ( array( 'name' => 'Digits', 'breakChainOnFailure' => true), array ( 'name' => 'Between', 'options' => array ( 'min' => 1, 'max' => 5, 'messages' => array('notBetween' => 'Point must be between %min% and %max%') ) ) ) ) ) ); Another option would be to replace Zend_Validate_Digits with Zend_Validate_Int (docmentation) depending of what error message you prefer to give to the user if he enters non valid data. Of course as suggested in the comments you could also use the Zend_Filter_Int if what you want is to handle any non valid data by fixing it yourself and do not give the user feedback about what he did wrong.
'breakChainOnFailure': true should be 'breakChainOnFailure'=> true